<script setup lang="ts">
import { onMounted } from 'vue';
import { initMap3d } from '../lib/map3d';
import { initMap2d } from '../lib/map2d';
import { env } from '../lib/env';


onMounted(async () => {
  // 创建一个URL对象
  const url = new URL(window.location.href);
  // 使用URLSearchParams获取查询参数
  const params = new URLSearchParams(url.search);
  const map2d = params.get('map2d'); 
  // 如果直接传入了mapid
  const mapid = params.get('mapid'); 
  if (mapid) {
    env.mapId = mapid;
  }
  // 如果直接传入了mapid的版本
  const version = params.get('version'); 
  if (version) {
    env.version = version;
  }
  const scaleZ = params.get('scaleZ'); 
  if (scaleZ) {
    env.scaleZ = +scaleZ || 5;
  }
  const baseZ = params.get('baseZ'); 
  if (baseZ) {
    env.baseZ = +baseZ;
  }
  const gridHelper = params.get('gridHelper'); 
  if (gridHelper) {
    env.gridHelper = gridHelper == "true";
  }
  const show3dpolyline = params.get('show3dpolyline'); 
  if (show3dpolyline === "false") {
    env.show3dpolyline = false;
  }
  const show3dpolyface = params.get('show3dpolyface'); 
  if (show3dpolyface === "false") {
    env.show3dpolyface = false;
  }
  const show3dpolymesh = params.get('show3dpolymesh'); 
  if (show3dpolymesh === "false") {
    env.show3dpolymesh = false;
  }
  const darkTheme = params.get('darkTheme'); 
  if (darkTheme) {
    env.darkTheme = darkTheme === "true";
  }
  const mapopenway = params.get('mapopenway'); 
  if (mapopenway) {
    env.mapopenway = mapopenway;
  }
  let background = params.get('background'); 
  if (background) {
    if (background.substring(0) != "#") {
      background = "#" + background;
    }
    env.background = background;
  }
  if (params.get('showMousePositionControl') === "false") {
    env.showMousePositionControl = false;
  }
  if (map2d !== "false") {
    // 2d地图模式, 3d做为一个图层
    initMap2d();
  } else {
    // 纯3d模式
    initMap3d();
  }
})

</script>

<template>
  <div id="map3dContainer"></div>
</template>

<style scoped>
#map3dContainer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: #000117;
}
</style>
